package com.nyist.springcloud.service.impl;

import com.nyist.springcloud.dao.PaymentDao;
import com.nyist.springcloud.entities.Payment;
import com.nyist.springcloud.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yangxiaogen
 * @date 2021/1/21 14:32
 */
@Service
public class PaymentServiceImpl implements PaymentService {

    @Autowired
    private PaymentDao paymentDao;

    @Override
    public Payment insertPay(Payment payment) {
        //Payment pay = this.queryPaymentByName(payment.getName());
        Payment pay = this.queryPaymentById(payment.getId());
        if (pay!=null){
            return new Payment();
        }
        int count = paymentDao.insertPay(payment);
        if (count > 0) {
            return payment;
        }
        return new Payment();
    }

    @Override
    public List<Payment> queryPayments() {
        return paymentDao.queryPayments();
    }

    @Override
    public Payment queryPaymentById(String id) {
        return paymentDao.queryPaymentById(id);
    }

    @Override
    public Payment queryPaymentByName(String name) {
        return paymentDao.queryPaymentByName(name);
    }

}
